package com.aidex.biz.controller;

import java.util.List;

import com.aidex.biz.service.LinshiDeptManageService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.utils.uuid.UUID;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.LinshiManage;
import com.aidex.biz.service.LinshiManageService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 临时督办Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/biz/bizLinshiManage")
public class LinshiManageController extends BaseController
{
    @Autowired
    private LinshiManageService linshiManageService;

    @Autowired
    private LinshiDeptManageService linshiDeptManageService;

    /**
     * 查询临时督办列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:list')")
    @GetMapping("/list")
    public R<PageInfo> list(LinshiManage linshiManage, HttpServletRequest request, HttpServletResponse response)
    {

        linshiManage.setPage(new PageDomain(request, response));
        return R.data(linshiManageService.findPage(linshiManage));
    }

    /**
     * 获取临时督办详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:query')")
    @GetMapping(value = "/{id}")
    public R<LinshiManage> detail(@PathVariable("id") String id)
    {
        return R.data(linshiManageService.get(id));
    }

    /**
     * 新增临时督办
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:add')")
    @Log(title = "临时督办", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  LinshiManage linshiManage)
    {
        linshiManage.setId(linshiManage.getUuid());
        linshiManage.setIsNewRecord();
        return R.status(linshiManageService.save(linshiManage));
    }

    /**
     * 修改临时督办
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:edit')")
    @Log(title = "临时督办", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated LinshiManage linshiManage)
    {
        return R.status(linshiManageService.save(linshiManage));
    }


    /**
     * 删除临时督办
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:remove')")
    @Log(title = "临时督办", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(linshiManageService.deleteLinshiManageByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(linshiManageService.findMaxSort(new LinshiManage()));
    }

    /**
     * 导出临时督办列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:export')")
    @Log(title = "临时督办", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(LinshiManage linshiManage)
    {


        List<LinshiManage> list = linshiManageService.findList(linshiManage);
        ExcelUtil<LinshiManage> util = new ExcelUtil<LinshiManage>(LinshiManage.class);
        return util.exportExcel(list, "临时督办数据");
    }


    /**
     * 新增临时督办
     */
    @PreAuthorize("@ss.hasPermi('biz:bizLinshiManage:edit')")
    @Log(title = "临时督办-发布", businessType = BusinessType.OTHER)
    @PostMapping("/fabu")
    public R fabu(@RequestBody @Validated  LinshiManage linshiManage)
    {
        if(linshiDeptManageService.batchInsert(linshiManage)>0){
            linshiManage.setStatus(LinshiManage.STATUS_DISABLE);
            return R.status(linshiManageService.save(linshiManage));
        }else{
            return R.fail("发布失败");
        }

    }



    @GetMapping("/getUUID")
    public R getUUID()
    {
        return R.data(UUID.fastUUID().toString());
    }

}
